<template>
  <div class="container">
    <!-- 搜索框开始 -->
    <section class="search">
      <div class="search_box">
        <i class="fa fa-search" aria-hidden="true"></i>
        <input type="text" placeholder="请输入关键词" />
      </div>
    </section>
    <!-- 搜索框结束 -->

    <!-- 轮播图开始 -->
    <section class="banner">
      <div class="banner_box">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="blue">
          <van-swipe-item v-for="item in slides" :key="item.src">
            <a :href="item.href" class="banner_a">
              <img class="banner_img" :src="item.src" alt />
            </a>
          </van-swipe-item>
        </van-swipe>
      </div>
    </section>
    <!-- 轮播图结束 -->

    <!-- 顶部导航栏开始 -->
    <section class="top_nav">
      <div
        class="nav_box"
        v-for="item in navs.items"
        :key="item.href"
        @click.stop="gotoDetail(item)"
      >
        <img :src="item.src" alt />
        <span>{{ item.name }}</span>
      </div>
    </section>
    <!-- 顶部导航栏结束 -->
    <!-- 空白标签开始 -->
    <section class="blank_box">
      <!-- vue的父传值属性 -->
      <KPBlank :height="blank.height" :bgcolor="blank.bgcolor"></KPBlank>
    </section>
    <!-- 空白标签结束 -->
    <!-- 关注公众号开始 -->
    <section class="gzh_box">
      <div class="mask" v-show="showQRCode" @click="hide()">
        <div class="modal" @click.stop="show()">
          <img class="code_pic" src="../assets/img/topright.png" alt />
          <div class="code_title">关注公众号</div>
          <div class="code_body">
            <div class="qrcode">
              <img :src="msg.qrcode" alt />
            </div>
          </div>
          <div class="code_footer">长按二维码识别图片或截图保存</div>
        </div>
      </div>
      <div class="left_box">
        <div class="info_left">
          <img :src="msg.logo" alt />
        </div>
        <div class="info_right">
          <p class="title">{{ msg.name }}</p>
          <p class="pro">{{ msg.desc }}</p>
        </div>
      </div>
      <div class="right_box">
        <div class="btn" @click="show()">关注</div>
      </div>
    </section>
    <!-- 关注公众号结束 -->
    <!-- 课程列表开始 -->
    <div class="index-section-box">
      <div class="index-section-title">
        <div class="index-section-title-text">{{ courseInfo.title }}</div>
        <div class="more" @click.stop="goToAllCourse()">
          <span>查看全部</span>
        </div>
      </div>
      <div class="index-section-body">
        <KPCourseItem v-for="i in courseInfo.items" :key="i.id" :item="i"></KPCourseItem>
      </div>
    </div>
    <!-- 课程列表结束 -->
    <!-- 技术支持开始 -->
    <TechSupport></TechSupport>
    <!-- 技术支持结束 -->
    <!-- 底部导航栏开始 -->
    <KPFoot type="home"></KPFoot>
    <!-- 底部导航栏结束 -->
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import Vue from "vue";
import { Swipe, SwipeItem } from "vant";
import KPBlank from "@/components/KPBlank.vue";
import KPCourseItem from "@/components/KPCourseItem.vue";
import KPFoot from "@/components/KPFoot.vue";
import TechSupport from "@/components/TechSupport.vue";
import { Lazyload } from "vant";

Vue.use(Swipe);
Vue.use(SwipeItem);
Vue.use(Lazyload);

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    KPBlank,
    KPCourseItem,
    KPFoot,
    TechSupport,
    TechSupport
  },
  data() {
    //这里存放数据
    return {
      blocks: [],
      slides: [],
      navs: [],
      blank: {},
      msg: {},
      showQRCode: false,
      courseInfo: {} // 录播课程信息
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    goToAllCourse: function() {
      this.$router.push({
        path: "/vod"
      });
    },
    hide() {
      this.showQRCode = false;
    },
    show() {
      this.showQRCode = true;
    },
    gotoDetail: function(item) {
      this.$router.push({
        //此处的属性名都是固定的
        path: "/vod/detail",
        query: {
          id: item.href.split("?")[1].split("=")[1]
        }
      });
    }
  },

  async created() {
    let res = await this.$request.get("/api/v2/viewBlock/page/blocks", {
      params: {
        platform: "h5",
        page_name: "h5-page-index"
      }
    });
    this.blocks = res.data;
    res.data.forEach(item => {
      // console.log(item);
      if (item.sign === "slider") {
        this.slides = item.config_render;
      }
      if (item.sign === "grid-nav") {
        this.navs = item.config_render;
      }
      if (item.sign === "blank") {
        this.blank = item.config_render;
        // console.log("我是空白标签的值", this.blank);
      }
      if (item.sign === "h5-gzh-v1") {
        this.msg = item.config_render;
        // console.log(this.msg);
      }
      if (item.sign === "h5-vod-v1") {
        this.courseInfo = item.config_render;
        // console.log(this.courseInfo);
      }
    });
  }
};
</script>

<style lang="less" scoped>
.container {
  height: 100vh;
  background: #f3f6f9;
  margin: 0 auto;
  max-width: 10rem;
  overflow-x: hidden;
  overflow-y: scroll;
  position: relative;
  .search {
    width: 100%;
    height: 1.333333rem;
    background: #fff;
    position: relative;
    display: flex;
    padding: 0.213333rem 0.4rem;
    .search_box {
      .fa.fa-search {
        width: 0.426667rem;
        height: 0.426667rem;
        line-height: 0.426667rem;
        position: absolute;
        top: 0.453333rem;
        left: 0.986667rem;
        cursor: pointer;
      }

      input {
        width: 9.2rem;
        height: 0.906667rem;
        background: #f5f5f5;
        border-radius: 0.453333rem;
        outline: none;
        border: none;
        padding-left: 1.333333rem;
        font-size: 0.373333rem;
      }
    }
  }
  .banner {
    width: 100%;
    height: 4rem;
    background-color: #fff;
    .banner_box {
      width: 92%;
      margin: 0 auto;
      border-radius: 0.4rem;
      overflow: hidden;
      .my-swipe .van-swipe-item {
        color: #fff;
        font-size: 0.533333rem;
        line-height: 4rem;
        text-align: center;
        .banner_a {
          display: block;
          width: 100%;
          .banner_img {
            width: 100%;
            height: 4rem;
          }
        }
      }
    }
  }

  .top_nav {
    display: flex;
    background-color: #fff;
    .nav_box {
      display: flex;
      flex: 1;
      align-items: center;
      flex-direction: column;
      padding: 0.266667rem;

      img {
        width: 1.333333rem;
        height: 1.333333rem;
      }

      span {
      }
    }
  }
  .gzh_box {
    height: auto;
    box-sizing: border-box;
    padding: 0.4rem;
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-direction: row;
    .mask {
      position: absolute;
      width: 100%;
      z-index: 999;
      top: 0;
      right: 0;
      left: 0;
      bottom: 0;
      background: rgba(0, 0, 0, 0.6);
      .modal {
        position: fixed;
        z-index: 999;
        width: 200px;
        height: 236px;
        top: calc(50% - 118px);
        left: calc(50% - 100px);
        background-color: #fff;
        border-radius: 8px;
        overflow: hidden;
        -webkit-animation: window-open 0.3s;
        animation: window-open 0.3s;
        display: flex;
        flex-direction: column;
        .code_pic {
          animation: window-open;
          position: absolute;
          top: 3px;
          right: 0;
          width: 64px;
          height: 67px;
        }

        .code_title {
          width: 100%;
          margin-top: 20px;
          height: 14px;
          font-size: 14px;
          font-weight: 500;
          color: #333;
          line-height: 14px;
          text-align: center;
        }

        .code_body {
          width: 100%;
          margin-top: 20px;
          height: 120px;
          display: flex;
          justify-content: center;
          .qrcode {
            width: 120px;
            height: 120px;
            img {
              width: 120px;
              height: 120px;
            }
          }
        }

        .code_footer {
          width: 100%;
          margin-top: 20px;
          height: 12px;
          font-size: 12px;
          font-weight: 400;
          color: #999;
          line-height: 12px;
          text-align: center;
        }
      }
    }
    .left_box {
      display: flex;
      align-items: center;
      .info_left {
        img {
          width: 1.333333rem;
          height: 1.333333rem;
          border-radius: 50%;
        }
      }

      .info_right {
        padding-left: 0.2rem;
        .title {
          width: 100%;
          height: 0.533333rem;
          font-size: 0.4rem;
          font-weight: 500;
          color: #171923;
          line-height: 0.533333rem;
          margin-top: 0.133333rem;
          overflow: hidden;
        }
        .pro {
          width: 100%;
          height: 0.32rem;
          font-size: 0.32rem;
          font-weight: 400;
          color: #999;
          line-height: 0.32rem;
          margin-top: 0.213333rem;
          overflow: hidden;
        }
      }
    }

    .right_box {
      display: flex;
      .btn {
        height: 0.64rem;
        width: 1.546667rem;
        text-align: center;
        line-height: 0.64rem;
        background: #3ca7fa;
        border-radius: 0.32rem;
        font-size: 0.373333rem;
        font-weight: 400;
        color: #fff;
        justify-content: center;
      }
    }
  }
  .index-section-box {
    width: 100%;
    margin-top: 0.266667rem;
    background: #fff;
    padding: 0.666667rem 0.4rem 0.533333rem 0.4rem;
    display: flex;
    flex-direction: column;

    .index-section-title {
      width: 100%;
      height: 0.506667rem;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 0.666667rem;

      .index-section-title-text {
        height: 0.506667rem;
        font-size: 0.506667rem;
        font-weight: 600;
        color: #333;
        line-height: 0.506667rem;
      }

      .more {
        display: inline-block;
        width: auto;
        height: 0.346667rem;
        font-size: 0.346667rem;
        font-weight: 400;
        color: #999;
        line-height: 0.346667rem;
        cursor: pointer;

        span {
        }
      }
    }

    .index-section-body {
      width: 100%;
    }
  }
}
</style>
